<?php

namespace app\common\model;

use think\Model;

class Admin extends Model
{

    /**
     * 添加管理员
     *
     * @param [type] $data
     * @return void
     */
    public function addInfo($data)
    {

    }

    /**
     * 变更管理员账户信息
     *
     * @param [type] $data
     * @param integer $aid
     * @return void
     */
    public function editInfo($data, $aid = 0)
    {
        if ($aid) {
            $info = $this->where('id', $aid)->find();

            if ($data['ad_tel'] != $info['ad_tel']) {
                $num = $this->where('ad_tel', $data['ad_tel'])->count();
                if ($num) {
                    return ['code' => 0 ,'msg' => '此手机号码已存在'];
                }
            }
            if ($data['ad_pwd']) {
                $data['ad_pwd'] = encrypt($data['ad_pwd']);
            } else {
                unset($data['ad_pwd']);
            }

            $this->where('id', $aid)->update($data);
        }

        return ['code' => 1, 'msg' => '操作成功'];
    }

    /**
     * 添加操作日志
     *
     * @param [type] $aid
     * @param [type] $adname
     * @param string $note
     * @return void
     */
    public function addLog($aid,$adname, $note = '')
    {
        $data = [
			'aid' => $aid,
			'ad_name' => $adname,
			'note' => $note,
			'create_time' => date('Y-m-d H:i:s')
		];

		return $this->insert($data);
    }
}
